#include "guiterm.hpp"
#ifndef PROGRAM_HPP
#define PROGRAM_HPP

class RemoteJob
	:public QObject
{
	Q_OBJECT
public:
	RemoteJob(Session *session);
	RemoteJob(Session *session, string cmd);
	~RemoteJob();
	
	void begin();
	
	Session *getSession();
	int getId() const;
	JobView *getView();
	bool getIsFinished();
	
	void reportError(string message);
	void reportMessage(string message);
	
	void beginOutput();
	void setRunState(string state);
	void programOutput(const char *data, int len);
	void outputFinished();
	
	void sendData(const char *data, int len);
	void createInputSender();
	void winch(int width, int height);
	void finish(int result, string leftoverInput="");
	
	void addFileView(FileView *view);
	
public slots:
	void finishSegment();
	void interrupt();
	void terminate();
	void kill();
	void pause();
	
protected:
	void addTextOutput();
	ServerConnection *startNestedSession();
	
	Session *session;
	StreamSender *inputSender;
	
	bool isLogin;
	bool isNestedShell;
	string command;
	bool started;
	bool isFinished;
	
	int jobid;
	JobView *view;
	
	TerminalEmulator *currentOutputModel;
	ScrollableTermView *currentTextSegment;
	
	void handleOSC(const char *&incomingData, int &incomingLen, int incomingPos);
	
	enum OSCState {
		stateNormal,
		stateEscSeen,
		stateOSC,
		stateOSCEscSeen,
	};
	OSCState state;
	
	StreamBuffer pendingOSC;
};

#endif
